package cn.seecoder.ai.controller;

import cn.seecoder.ai.model.vo.AnalysisConfigVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.AnalysisConfigService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DingXiaoyu
 * @date 2023/4/13 14:24
 */
@Slf4j
@RestController
@RequestMapping("${apiPrefix}/analysis/configs")
public class AnalysisConfigController {

    @Autowired
    AnalysisConfigService analysisConfigService;

    @ApiOperation("创建数据统计配置")
    @PostMapping
    public ResultVO<AnalysisConfigVO> addAnalysisConfig(@RequestBody AnalysisConfigVO analysisConfigVO){
        return ResultVO.buildSuccess(analysisConfigService.addAnalysisConfig(analysisConfigVO));
    }

    @ApiOperation("获取配置")
    @GetMapping("/all/{userId}")
    public ResultVO<List<AnalysisConfigVO>> getAnalysisConfigs(@PathVariable(value = "userId")Integer userId){
        return ResultVO.buildSuccess(analysisConfigService.getAnalysisConfigs(userId));
    }

    @ApiOperation("删除配置")
    @DeleteMapping("/{configId}")
    public ResultVO<Boolean> deleteAnalysisConfig(@PathVariable(value = "configId")Integer configId){
        return ResultVO.buildSuccess(analysisConfigService.deleteAnalysisConfig(configId));
    }

    @ApiOperation("配置详细信息")
    @GetMapping("/{configId}")
    public ResultVO<AnalysisConfigVO> getAnalysisConfig(@PathVariable(value = "configId")Integer configId){
        return ResultVO.buildSuccess(analysisConfigService.getAnalysisConfig(configId));
    }
}
